//
//  SSSMerchantHistoryBenefitCell.m
//  SSSMerchant
//
//  Created by xnxin on 2017/3/22.
//  Copyright (c) 2017 xnxin. All rights reserved.
//

#import "SSSMerchantHistoryBenefitCell.h"
#import <Masonry/Masonry.h>
#import "SSSMerchantHistoryBenefitCellModel.h"
#import "NSDateAddition.h"
#import "NSNumber+Addition.h"

@interface SSSMerchantHistoryBenefitCell()

@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *moneyLabel;
@property(readonly) SSSMerchantHistoryBenefitCellModel *model;

@end

@implementation SSSMerchantHistoryBenefitCell
@dynamic model;

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (!self) {
        return nil;
    }

    self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows_right"]];
    self.dateLabel = [UILabel new];
    self.dateLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.dateLabel];
    self.moneyLabel = [UILabel new];
    self.moneyLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.moneyLabel];

    self.graylineEdgeInset = UIEdgeInsetsMake(0, 15, 0, 15);
    [self setupConstraint];
    return self;
}

- (void)setupConstraint {

    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView.mas_leading).offset(15);
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];

    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.trailing.equalTo(self.contentView.mas_trailing).offset(-10);
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
}

- (void)setModel:(SSSMerchantHistoryBenefitCellModel*)model {
    _model = model;

    self.dateLabel.text = [model.date xhstringWithFormat:@"yyyy-MM-dd"];
    self.moneyLabel.text = model.money.moneyValue;
}


@end
